package com.flyme.module.exam.client.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 测评项目
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
public enum AbilityItemEnum implements IEnum {

    serve("serve", "服务"),
    finance("finance", "财务"),
    maintain("maintain", "维护"),
    develop("develop", "发展"),
    marketing("marketing", "营销"),
    manage("manage", "管理"),
    education("education", "学历"),
    work("work", "工作"),
    synthesis("synthesis","综合");

    public String text;
    @EnumValue
    public String code;

    AbilityItemEnum(String code, String text) {
        this.text = text;
        this.code = code;
    }

    AbilityItemEnum(String code) {
        this.text = getText(code);
        this.code = code;
    }


    public static String getText(Object code) {
        String v = "";
        for (AbilityItemEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.text;
                break;
            }
        }
        return v;
    }

    public static String getName(String code) {
        String v = "";
        for (AbilityItemEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.name();
                break;
            }
        }
        return v;
    }

    public static AbilityItemEnum getEnum(String code) {
        for (AbilityItemEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                return accountTypeEnum;
            }
        }
        return null;
    }

    public static Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        for (AbilityItemEnum educationEnum : values()) {
            map.put(educationEnum.code, educationEnum.text);
        }
        return map;
    }

    public static void main(String[] args) {
        //System.out.print(getName("OT_VIP"));
        String duan = "铂金V三星";
        Integer num = duan.length();
        System.out.println(duan.substring(0, (num - 2)));
        System.out.println(duan.substring(num - 2));
    }

    @Override
    public Serializable getValue() {
        return this.code;
    }

}
